/*
 * @Author: 江舟 jijiangzhou@recycloud.cn
 * @Date: 2024-03-21 15:02:20
 * @LastEditors: 江舟 jijiangzhou@recycloud.cn
 * @LastEditTime: 2024-07-04 09:17:59
 * @FilePath: \vite-project\src\hooks\useLogin.ts
 */
import { useLocation, useNavigate } from 'react-router-dom-v5-compat';
import { useTokenStore } from '../store/user';

export default function useLogin() {
    const { token, claerToken } = useTokenStore();
    const location = useLocation();
    const navigate = useNavigate();
    function handleLogin() {
        if (!location.pathname.includes('/login')) {
            // 登录重定向
            // location.replace(`${location.origin + process.env.BUILD_URL}/login`);
            navigate('/login', { replace: true });
        }
    }

    return {
        token,
        handleLogin,
        claerToken,
    };
}
